/*
 *
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: UtilsApi.java
 *   @Date: 11/29/18 3:21 PM
 *   @Author: chenjun
 *   @Copyright（C）: 2018 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 *
 */

package io.bhex.sdk.utils;

import android.content.Context;

import java.io.File;

import io.bhex.baselib.network.response.ResultResponse;
import io.bhex.sdk.account.bean.UpdateResponse;
import io.bhex.sdk.Urls;
import io.bhex.sdk.utils.bean.AnnouncementsResponse;
import io.bhex.sdk.utils.bean.BannerResponse;
import io.bhex.sdk.utils.bean.UploadImgResponse;
import io.bhex.baselib.network.BParamsBuilder;
import io.bhex.baselib.network.HttpUtils;
import io.bhex.baselib.network.listener.SimpleResponseListener;
import io.bhex.baselib.network.params.PostParams;
import io.bhex.baselib.network.response.BaseResponse;
import io.bhex.baselib.utils.DevicesUtil;

public class UtilsApi {
    public static void UploadImg(String imagePath, SimpleResponseListener<UploadImgResponse> listener){
        PostParams params;
        params = BParamsBuilder.post()
                .url(Urls.API_USER_UPLOAD_IMAGE)
                .addFile("upload_image_file", new File(imagePath))
                .build();
        HttpUtils.getInstance().request(params, UploadImgResponse.class,listener);
    }

    public static void UploadVerifyImg(String imagePath, SimpleResponseListener<UploadImgResponse> listener){
        PostParams params;
        params = BParamsBuilder.post()
                .url(Urls.API_VERIFY_UPLOAD_IMAGE)
                .addFile("upload_image_file", new File(imagePath))
                .build();
        HttpUtils.getInstance().request(params, UploadImgResponse.class,listener);
    }

    public static void UploadGuildImg(String imagePath, SimpleResponseListener<UploadImgResponse> listener){
        PostParams params;
        params = BParamsBuilder.post()
                .url(Urls.API_GUILD_UPLOAD_IMAGE)
                .addFile("image_file", new File(imagePath))
                .build();
        HttpUtils.getInstance().request(params, UploadImgResponse.class,listener);
    }

    public static void RequestAnnouncements(SimpleResponseListener<AnnouncementsResponse> listener) {

        PostParams params = BParamsBuilder.post()
                .url(Urls.API_ANNOUNCEMENTS_LIST_URL)
                .build();
        HttpUtils.getInstance().request(params, AnnouncementsResponse.class, listener);
    }

    /**
     * 请求Banner列表
     * @param listener
     */
    public static void RequestBanners(SimpleResponseListener<BannerResponse> listener) {

        PostParams params = BParamsBuilder.post()
                .url(Urls.API_BANNER_LIST_URL)
                .build();
        HttpUtils.getInstance().request(params, BannerResponse.class, listener);
    }

    public static void RequestSendPushToken(Context context, String token, String clientID, String type){
        PostParams params;
        params = BParamsBuilder.post()
                .url(Urls.API_PUSH)
                .addParam("app_id", DevicesUtil.getPackageName(context))
                .addParam("app_version", DevicesUtil.getAppVersionName(context))
                .addParam("device_type", "android")
                .addParam("device_version", DevicesUtil.getSdkVersion(context))
                .addParam("device_token", token)
                .addParam("client_id", clientID)
                .addParam("push_type", type)
                .build();

        HttpUtils.getInstance().request(params, BaseResponse.class, new SimpleResponseListener<BaseResponse>() {

            @Override
            public void onSuccess(BaseResponse data) {
                super.onSuccess(data);

            }

        });
    }

    /**
     * 下载更新APP的方法
     */
    public static void RequestCheckVersionUpdate(final Context context, SimpleResponseListener<UpdateResponse> listener) {
        PostParams params;
        params = BParamsBuilder.post()
                .url(Urls.API_UPDATE)
                .addParam("app_id", DevicesUtil.getPackageName(context))
                .addParam("app_version", DevicesUtil.getAppVersionName(context))
                .addParam("device_type", "android")
                .addParam("device_version", DevicesUtil.getSdkVersion(context))
                .build();


        HttpUtils.getInstance().request(params, UpdateResponse.class, listener);
    }

    /**
     * 下载更新APP的方法
     */
    public static void RequestOpenOption(SimpleResponseListener<ResultResponse> listener) {
        PostParams params;
        params = BParamsBuilder.post()
                .url(Urls.API_OPTION_OPEN)
                .build();

        HttpUtils.getInstance().request(params, ResultResponse.class, listener);
    }
}
